from heapq import heappush, heappop

def heapsort(iterable):
     'Equivalent to sorted(iterable)'
     h = []
     for value in iterable:
         heappush(h, value)
     print h
     return [heappop(h) for i in range(len(h))]

num = [3,5,7,213,765,2]
print heapsort(num)
